package districting;

import java.util.Comparator;

import com.vividsolutions.jts.algorithm.Angle;
import com.vividsolutions.jts.geom.Coordinate;

public class CoordinateAngleComparator implements Comparator<Coordinate> {
   Double angle;

   public CoordinateAngleComparator(Double angle) {
      this.angle = angle;
   }

   @Override
   public int compare(Coordinate c0, Coordinate c1) {
      double angleBetween = Angle.angle(c0, c1);
      double diff = Angle.normalize(angleBetween - angle);
      if (diff > 0) {
         return -1;
      } else if (diff < 0) {
         return 1;
      }
      return 0;
   }

}
